//********************************************************************************
//	BootLoader.js
//		This file is responsible for instatiating a function to load functions and
//		for creating the universe.
//
//	Author: Alex Hanson
//	Revisions:
//		2013-08-20 AJH Created
//********************************************************************************

//Constructor
function BootLoader() {
	this.loadingDIV = this.loadLoading();
}

//Function to boot everything.
BootLoader.prototype.boot = function() {
	//TODO Show Loading Screen
	this.showLoading();
	
	//TODO Check Browser
	
	//TODO Load Game Libraries
	this.loadFile("lib","Universe.js",this.loadingDIV);
	this.loadFile("lib","Keyboard.js",this.loadingDIV);
	
	//TODO Instantiate Game Objects
	var uni = new Universe();
	new Keyboard(uni);
	
	
	//TODO Remove Loading Screen
	this.hideLoading();
}

//Function to load more code.
BootLoader.prototype.loadFile = function (directory,filename,div) {
	//Make sure that we received valid parameters
	if ((directory=="")||(filename=="")) return "";
	
	//Update Loading Screen
	div.innerHTML = "Loading...\n"+directory+"\\"+filename
	
	if (directory=="lib") { //If javascript file
		var file=document.createElement('script');
		file.setAttribute("type","text/javascript");
		file.setAttribute("src",directory+"\\"+filename);
	} else if (directory=="css") { //If CSS file
		var file=document.createElement('link');
		file.setAttribute("rel","stylesheet");
		file.setAttribute("type","text/css");
		file.setAttribute("href",directory+"\\"+filename);
	}
	document.getElementsByTagName("head")[0].appendChild(file);
}

//Function load Loading Screen
BootLoader.prototype.loadLoading = function() {
	this.loadFile("css","LoadingScreen.css");
	var div = document.createElement('div');
	div.id = 'loadingScreen';
	div.innerHTML = "Loading...";
	document.getElementsByTagName("body")[0].appendChild(div);
	return div;
}

//Function show Loading Screen
BootLoader.prototype.showLoading = function () {
	document.getElementById('loadingScreen').style.visibility="visible";
}

BootLoader.prototype.hideLoading = function() {
	document.getElementById('loadingScreen').style.visibility="hidden";
}